<%@page import="com.netistate.pojo.DemoHistory"%>
<%@page import="com.netistate.pojo.Demo"%>
<%@page import="com.netistate.pojo.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.netistate.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>project</title>
     <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/jquery-min.js"></script> 
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/demo/demo.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
    <style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
  	</head>
  	<body>
    
	<div id="xtab">
		<a id="rightDiv0_tab" href="#" class='homelink curren' onclick=""><span style="cursor:pointer;">Demo页面</span></a>
		<a id="rightDiv1_tab" href="#" class='homelink' onclick="transition()"><span style="cursor: pointer;">产品页面</span></a>
	</div>
	<div class="toolbar" >
   		<span style="color:red">当前位置：查看Demo机信息</span>
	    <a href="#" class='buttonlink txbtip' title='添加机器' onclick="add()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>添加机器</a>  
	    <a href="#" id="queryProjectButton" class='buttonlink txbtip' onclick="notHiddenDiv()" title='机器查询'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>机器查询</a> 
	    <%-- <a href="#" class='buttonlink txbtip' title='查看产品状态' style='float:right;' onclick="transition()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/switch_main.png'/>切换到查看产品界面</a> --%>  
	</div>
	
	<div id="productQuery" name="productQuery" class="toolbar" style="display:block;overflow:hidden;">
	    <form id="queryDemoByCondition" name="productQuery_condition" action="queryDemoByCondition.action" method="post" onSubmit="">
	        <table>
	           <tr>
	                <td class="td_title" title="Demo机序列号"><img alt="" src="${pageContext.request.contextPath}/images/common/search.png">Demo机序列号：</td>
	                <td class="td_title">
	                    <select id="dtype" name="demoSeqNo" style="width:100px;">
							<option value="所有">所有</option>
							 <%	List<Demo> demoList = (List<Demo>)request.getSession().getAttribute("demoList");
							 	String queryDemoSeqNo = (String)request.getAttribute("queryDemoSeqNo");
								for(Demo d : demoList){
								if(d.getSeqNo().equals(queryDemoSeqNo)){%>
								<option title="<%=queryDemoSeqNo %>" selected value="<%=queryDemoSeqNo%>"><%=queryDemoSeqNo %></option>
							<%  }else{ %>
							 	<option title="<%=d.getSeqNo() %>" value="<%=d.getSeqNo() %>"><%=d.getSeqNo() %></option>
							 <% }}%>
	                    </select>
	                </td>
		            <td><input type="submit" value="查询" title="查询"/></td>
	           </tr>
	        </table>
	    </form>
	</div>
	
	<div id="rcon_onepage" style="width:100%; height:90%; overflow-y:scroll; border: 1px solid;">
		<table id="dArticleList" width="100%" border="0" cellpadding="0" cellspacing="1" class="resizable overTd">
			<thead>
			<tr class="fixHead">
				<td class="td1" style="cursor:pointer" width="8%">Demo机号码	</td>
				<td class="td1" style="cursor:pointer" width="10%">序列号	</td>
				<td class="td1" style="cursor:pointer" width="7%">License截止日期</td>
				<td class="td1" style="cursor:pointer" width="10%">Demo机所在处</td>
				<td class="td1" style="cursor:pointer" width="5%">节点数</td>
				<td class="td1" style="cursor:pointer" width="7%">定制模块</td>
				<td class="td1" style="cursor:pointer" width="8%">硬件提供商</td>
				<td class="td1" style="cursor:pointer" width="10%">硬件配置</td>					
				<td class="td1" style="cursor:pointer" width="15%">备注</td>
				<td class="td1" style="cursor:pointer" width="7%">出/入库动作</td>
				<td class="td1" colspan="3">操作</td>
			</tr>
               </thead>
               <tbody>
				<%
				List<Demo> list = new ArrayList<Demo>();
				List<Demo> dlist = (List<Demo>)request.getAttribute("dList");
				if(dlist == null){
					list = (List<Demo>)request.getSession().getAttribute("demoList");
				}else{
					list = dlist;
				}
			 for(Demo d : list){
			 	int id = d.getId();
			 %>
		       <tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
			       <td title="<%=d.getOrders() %>" align="center" class="td2 txbtip" ><%=d.getOrders() %>&nbsp;</td>
			       <td title="<%=d.getSeqNo() %>" style="cursor: hand;text-overflow:ellipsis;overflow:hidden;" align="center" class="td2 txbtip" ><%=d.getSeqNo() %>&nbsp;</td>
				   <td title="<%=d.getLicense() %>" align="center" class="td2 txbtip" ><%=d.getLicense()%>&nbsp;</td>
				   <td title="<%=d.getDemoAddress() %>" align="center" class="td2 txbtip" ><%=d.getDemoAddress()%>&nbsp;</td>
				   <td title="<%=d.getNodes() %>" align="center" class="td2 txbtip" ><%=d.getNodes() %>&nbsp;</td>
			       <td title="<%=d.getModule() %>" align="center" class="td2 txbtip" ><%=d.getModule() %>&nbsp;</td>
			       <td title="<%=d.getHardwareSource() %>" style="cursor: hand;text-overflow:ellipsis;overflow:hidden;" align="center" class="td2 txbtip" ><%=d.getHardwareSource() %>&nbsp;</td>
			       <td title="<%=d.getProductConfig() %>" style="cursor: hand;text-overflow:ellipsis;overflow:hidden;" align="center" class="td2 txbtip" ><%=d.getProductConfig() %>&nbsp;</td>				       
			       <td title="<%=d.getNote() %>" align="left" class="td2 txbtip" ><%=d.getNote() %>&nbsp;</td> 
			       <td title="<%=d.getModule() %>" align="center" class="td2 txbtip" >
			       	<%if(d.getState() == 0){ %>
			       	在库中
			       	<%} else { %>
			       	出库中
			       	<%} %>
			       </td>
		          <td align="center" class="td2 txbtip">
		          	<%if(d.getState() == 0){ %>
				     <a href="#" class='buttonlink txbtip' title='出库' onclick="editOut(<%=id%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/arrow_return_090.png'/>出库</a>
				     <%}else{ %>
				     <a href="#" class='buttonlink txbtip' title='入库' onclick="editIn(<%=id%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/arrow_return_091.png'/>入库</a>
				     <%} %>
			      </td>
			      <td align="center" class="td2 txbtip">
				      <%-- <a href="#" class='buttonlink txbtip' title='删除' onclick="del('<%=id%>','你确定要删除？')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/delete.png'/></a> --%>
				      <a href="#" class='buttonlink txbtip' title='修改' onclick="editDemo('<%=id%>')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/edit.png'/></a>
			      </td>
				  <td align="center" class="td2 txbtip">
				      <a href="#" class='buttonlink txbtip' title='查看全部记录' onclick="findOneDemo(<%=d.getOrders()%>)" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/search.png'/></a>
			      </td>
					<%} %>	
					</tr>  
               </tbody>

		</table>
	</div>
		
	<script type="text/javascript" >
	
		//编辑demo,只能编辑五个状态（license到期日期，节点，模块，描述，硬件配置）
		function editDemo(id){
			AjaxUtil.request({
				url : 'edit_demo.action',
				params : {id:id},
				success : function(responseText){
		         PigossMsg.show("${pageContext.request.contextPath}/jsp/demo/editLessDemo.jsp?id="+id,"修改Demo信息",500,460,"EditDemo.editLessDemo()");
				},
				failure : function(){
				 PigossMsg.alert("编辑失败!");
				}
			});
		}
	
		//查看这台demo的所有记录
		function findOneDemo(orders){
			AjaxUtil.request({
				url : 'findOneDemo.action',
				params : {orders:orders},
				success : function(responseText){
		         PigossMsg.showWin("${pageContext.request.contextPath}/jsp/demo/showOneDemo.jsp","显示Demo机信息",500,460);
				},
				failure : function(){
				 PigossMsg.alert("查询失败!");
				}
			});
			
		};
		
	
		//添加Demo设备
		function add(){
	    	PigossMsg.show("${pageContext.request.contextPath}/jsp/demo/addDemo.jsp","添加机器",500,460,"AddDemo.savedemo()");
		}
		
		//入库信息修改
		function editIn(id){
			AjaxUtil.request({
				url : 'edit_demo.action',
				params : {id:id},
				success : function(responseText){
		         PigossMsg.show("${pageContext.request.contextPath}/jsp/demo/editInDemo.jsp?id="+id,"入库操作",500,460,"EditDemo.editInDemo()");
				},
				failure : function(){
				 PigossMsg.alert("编辑失败!");
				}
			});
		};
		
		//入库时信息的填写
		function editInDemoMsg(obj){
				var note = document.getElementById("note");
			if(obj.checked){
				note.removeAttribute("disabled");
			} else {
				note.setAttribute('disabled','disabled');
			};
		};
		
		
		//出库信息的修改
		function editOut(id){
	   		AjaxUtil.request({
				url : 'edit_demo.action',
				params : {id:id},
				success : function(responseText){
		         PigossMsg.show("${pageContext.request.contextPath}/jsp/demo/editOutDemo.jsp?id="+id,"出库操作",500,460,"EditDemo.editConfig()");
				},
				failure : function(){
				 PigossMsg.alert("编辑失败!");
				}
			});
	    }
	    
	    //删除Demo
	    function del(id,msg){
	        this.msg = msg;
	        PigossMsg.confirm(this.msg,null,function yesHandler(){EditDemo.del(id)},function noHandler(){});
	    }
		
		//查看产品状态
		function transition(){
			AjaxUtil.request({
				url : "findAllProduct.action",
				params : {},
				success : function(responseText){
   					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/demo/product.jsp";
				}, 
				failure : function(){
					PigossMsg.alert("添加失败!");
				}
			});		
		}
		
		//隐藏查询工具栏
		function notHiddenDiv(){
	        var idDiv = document.getElementById('productQuery');
	        if(idDiv.style.display=='none'){
	            idDiv.style.display='block'; 
	        }else{
	           idDiv.style.display='none'; 
	        };
	    };
	    
	    //增加demo时，模块的切换
	    function changeModule(){
	    	var module = document.getElementById("module").value;
	    	var customModule = document.getElementById("customModule");
	    	if(module == "定制模块"){
	    		customModule.style.display = 'inline';
	    	}else{
	    		customModule.style.display = 'none';
	    	};
	    };
	    
	    //修改demo时，模块的切换
	    function changeEditModule(){
	    	var module = document.getElementById("editModule").value;
	    	var showEditModule = document.getElementById("showEditModule");
	    	if(module == "定制模块"){
	    		showEditModule.style.display = 'inline';
	    	}else{
	    		showEditModule.style.display = 'none';
	    	};
	    };
	    
	    
	  	initTableWidget('dArticleList',Array('S','S',"S",'S','S','S','S','S','S',false));
	  	
	</script>
       
  </body>
</html>
